# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from spmi.dwd.spmi.dwd_piece_change_daily_detail_dt import spmi_dwd__dwd_piece_change_daily_detail_dt
from spmi.dwd.spmi import spmi_dwd__dwd_operater_change_daily_detail_dt
from spmi.dwd.spmi import spmi_dwd__dwd_transfer_change_daily_detail_dt
from spmi.dim.spmi import spmi_dim__dim_ibk_network_cost_control_center_base
from spmi.dim.spmi import spmi_dim__dim_ibk_sz_bill_config_base
from spmi.dim.spmi import spmi_dim__dim_ibk_increase_product_config_base
from spmi.dim.spmi import jms_dim__dim_network_whole_massage_check
from spmi.ods.mysql.ibk import spmi_ods__ibk_increase_day_report
from spmi.dwd.spmi import spmi_dwd__dwd_ibk_increase_day_report_daily_detail_dt

spmi_dws__dws_piece_transfer_operater_change_daily_summary = SparkSqlOperator(
    task_id='spmi_dws__dws_piece_transfer_operater_change_daily_summary',
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    name='spmi_dws__dws_piece_transfer_operater_change_daily_summary_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi/dws/spmi/dws_piece_transfer_operater_change_daily_summary/execute.sql',
    retries=0,
    pool='spmi_piece',
    driver_memory='4G' , 
    driver_cores=2 , 
    executor_cores=2 , 
    executor_memory='4G' , 
    email=['jarl.huang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    num_executors=10 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 12 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          'spark.sql.shuffle.partitions': 200,
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 70,  # 每天生成 20 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 70,  # 每天生成 20 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=1),
)

spmi_dws__dws_piece_transfer_operater_change_daily_summary <<  [
    spmi_dwd__dwd_piece_change_daily_detail_dt,
    spmi_dwd__dwd_operater_change_daily_detail_dt,
    spmi_dwd__dwd_transfer_change_daily_detail_dt,
    spmi_dim__dim_ibk_network_cost_control_center_base,
    spmi_dim__dim_ibk_sz_bill_config_base,
    spmi_dim__dim_ibk_increase_product_config_base,
    jms_dim__dim_network_whole_massage_check,
    spmi_dwd__dwd_ibk_increase_day_report_daily_detail_dt
]
